<template>
    <div >
      <zh-card title="文件分类树">
        <zh-tree
            :height="362"
            ref="classTreeRef"
            show-checkbox
            :showSearch="false"
            :url="VITE_FILE_API_URL+'fileClassM0005'"
            :nodeLevel="1"
            :expand-on-click-node="false"
            :queryParam="queryTreeParam"
            node-key="key"
            :props="{ label: 'title' }"
            @node-click="onNodeClick"
        ></zh-tree>
     
      </zh-card>
     
    </div>
</template>

<script lang="ts" setup name="fileClassTree">
const VITE_FILE_API_URL = import.meta.env.VITE_FILE_API_URL as string+'/doc/api/';


const selectNode: any = ref(null);
const fileClassInfo = ref({ fileClassCode: '', parentCode: null,  parentClassTitle: null, secrecyLevel: null });
const saveType = ref('edit');
const classTreeRef = ref<any>({
});

const state = reactive({
  oldSelectKey:''
});

// ------------------变量区------------------------------
const queryTreeParam=ref({parentKey:''});
const emit = defineEmits(['nodeClick']);

//--------------------------定义调用方法--------------------------------------------------

const onNodeClick = (node) => {
  // console.log('xxx:'+classTreeRef.getCheckedKeys);
  //点击树节点触发事件
  if(fileClassInfo.value.fileClassCode == node.key){
    classTreeRef.value.setCurrentKey(null);
    selectNode.value = {key:null};
    fileClassInfo.value.fileClassCode = '';
  }else{
    selectNode.value = node;
    fileClassInfo.value.fileClassCode = node.key;
  }
  saveType.value = 'edit';
  emit('nodeClick');
};

function refreshTree(){
  classTreeRef.value.query();
}

function getCheckedKeys(){
  // console.log("bbb")
  // console.log(classTreeRef.value.getCheckedKeys())
  return classTreeRef.value.getCheckedKeys();
}


//------------设置给父组件调用的数据/方法(组件)-----------
defineExpose({fileClassInfo,selectNode,refreshTree,classTreeRef,getCheckedKeys});
</script>
